#!/bin/bash

fmt_errs=$(hg st -A | awk '$1 ~ /[ACM]/ && $2 ~ /go$/ { print $2 }' | xargs gofmt -l)
#fmt_errs=$(find . -name '*.go' -exec gofmt -l {} \;)
err_count=$(echo $fmt_errs | awk '{print NF}')

if [ "$err_count" != 0 ]; then
  echo "gofmt errors: $err_count" >&2
  echo "$fmt_errs" >&2
  echo "run ./misc/hg/gofmt-all to fix" >&2
  exit 1
fi
